<template>
  <div class="not-found-container">
    <div class="not-found-content">
      <!-- 动态错误插图 -->
      <div class="error-illustration">
        <div class="error-circle">
          <div class="error-inner">
            <span class="error-text">404</span>
          </div>
        </div>
        <div class="error-shadow"></div>
      </div>

      <!-- 错误信息 -->
      <div class="error-message">
        <h1 class="error-title">页面不存在</h1>
        <p class="error-description">
          您访问的页面可能已被移除、重命名或暂时不可用
        </p>
      </div>

      <!-- 操作按钮 -->
      <div class="action-buttons">
        <el-button
            type="primary"
            size="large"
            @click="goBack"
            class="action-button"
        >
          <el-icon><ArrowLeft /></el-icon>
          返回上一页
        </el-button>

        <el-button
            type="success"
            size="large"
            @click="goHome"
            class="action-button"
        >
          <el-icon><HomeFilled /></el-icon>
          返回首页
        </el-button>
      </div>

      <!-- 搜索框 -->
      <div class="search-container">
        <p class="search-hint">或者尝试搜索您需要的内容：</p>
        <el-input
            v-model="searchQuery"
            placeholder="请输入关键词搜索"
            size="large"
            class="search-input"
            @keyup.enter="performSearch"
        >
          <template #append>
            <el-button
                type="primary"
                @click="performSearch"
                class="search-button"
            >
              <el-icon><Search /></el-icon>
              搜索
            </el-button>
          </template>
        </el-input>
      </div>
    </div>

    <!-- 页脚 -->
    <div class="not-found-footer">
      <p>© {{ currentYear }} 校园管理系统 - 技术支持: support@campus.edu</p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import {
  ArrowLeft,
  HomeFilled,
  Search
} from '@element-plus/icons-vue';

const router = useRouter();
const searchQuery = ref('');
const currentYear = new Date().getFullYear();

// 返回上一页
const goBack = () => {
  if (window.history.length > 1) {
    router.go(-1);
  } else {
    router.push('/');
  }
};

// 返回首页
const goHome = () => {
  router.push('/login');
};

// 执行搜索
const performSearch = () => {
  if (searchQuery.value.trim()) {
    router.push({
      path: '/search',
      query: { q: searchQuery.value.trim() }
    });
  }
};
</script>

<style scoped>
.not-found-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4efe9 100%);
  padding: 20px;
  box-sizing: border-box;
}

.not-found-content {
  max-width: 700px;
  width: 100%;
  text-align: center;
  padding: 40px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 1;
}

.error-illustration {
  position: relative;
  margin: 0 auto 40px;
  width: 300px;
  height: 300px;
}

.error-circle {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 250px;
  height: 250px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6b6b 0%, #ff8e8e 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  animation: float 3s ease-in-out infinite;
}

.error-inner {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: white;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.error-text {
  font-size: 80px;
  font-weight: 900;
  color: #ff6b6b;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.error-shadow {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 20px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 50%;
  filter: blur(5px);
  animation: shadow 3s ease-in-out infinite;
}

.error-message {
  margin-bottom: 40px;
}

.error-title {
  font-size: 36px;
  color: #2c3e50;
  margin-bottom: 20px;
  font-weight: 700;
}

.error-description {
  font-size: 18px;
  color: #7f8c8d;
  line-height: 1.6;
  max-width: 500px;
  margin: 0 auto;
}

.action-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 40px;
  flex-wrap: wrap;
}

.action-button {
  padding: 15px 30px;
  font-size: 16px;
  border-radius: 50px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.action-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.15);
}

.search-container {
  margin-top: 30px;
}

.search-hint {
  font-size: 16px;
  color: #7f8c8d;
  margin-bottom: 15px;
}

.search-input {
  max-width: 500px;
  margin: 0 auto;
}

.search-input :deep(.el-input__inner) {
  border-radius: 50px 0 0 50px !important;
  height: 50px;
  padding: 0 20px;
}

.search-input :deep(.el-input-group__append) {
  border-radius: 0 50px 50px 0 !important;
  padding: 0;
  overflow: hidden;
}

.search-button {
  height: 50px;
  padding: 0 30px;
  border-radius: 0 50px 50px 0 !important;
}

.not-found-footer {
  margin-top: 50px;
  text-align: center;
  color: #7f8c8d;
  font-size: 14px;
}

/* 动画效果 */
@keyframes float {
  0% {
    transform: translateX(-50%) translateY(0px);
  }
  50% {
    transform: translateX(-50%) translateY(-20px);
  }
  100% {
    transform: translateX(-50%) translateY(0px);
  }
}

@keyframes shadow {
  0% {
    width: 200px;
    opacity: 0.4;
  }
  50% {
    width: 180px;
    opacity: 0.2;
  }
  100% {
    width: 200px;
    opacity: 0.4;
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .error-illustration {
    width: 200px;
    height: 200px;
  }

  .error-circle {
    width: 180px;
    height: 180px;
  }

  .error-inner {
    width: 140px;
    height: 140px;
  }

  .error-text {
    font-size: 60px;
  }

  .error-title {
    font-size: 28px;
  }

  .action-buttons {
    flex-direction: column;
    align-items: center;
  }

  .action-button {
    width: 100%;
    max-width: 300px;
  }
}

@media (max-width: 480px) {
  .not-found-content {
    padding: 20px;
  }

  .error-illustration {
    width: 150px;
    height: 150px;
  }

  .error-circle {
    width: 130px;
    height: 130px;
  }

  .error-inner {
    width: 100px;
    height: 100px;
  }

  .error-text {
    font-size: 40px;
  }
}
</style>
